a11y: Implement role and state change in GtkSwitch
authorEmmanuele Bassi <ebassi@gnome.org>
Fri, 17 Jul 2020 13:31:02 +0000 (14:31 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Sun, 26 Jul 2020 19:31:15 +0000 (20:31 +0100)
Set the "switch" role, and update the "checked" state when the :active
property is toggled.

gtk/gtkswitch.c

index 64e9cc379bfd909a46c4b65c4b85121945c1f825..9e4aff1bcba6f1abc10c7736bd1b84605d62ec05 100644 (file)
@@ -606,6 +606,8 @@ gtk_switch_class_init (GtkSwitchClass *klass)
   g_object_class_override_property (gobject_class, PROP_ACTION_TARGET, "action-target");
 
   gtk_widget_class_set_css_name (widget_class, I_("switch"));
+
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_SWITCH);
 }
 
 static void
@@ -700,6 +702,10 @@ gtk_switch_set_active (GtkSwitch *self,
 
       g_object_notify_by_pspec (G_OBJECT (self), switch_props[PROP_ACTIVE]);
 
+      gtk_accessible_update_state (GTK_ACCESSIBLE (self),
+                                   GTK_ACCESSIBLE_STATE_CHECKED, is_active,
+                                   -1);
+
       gtk_widget_queue_allocate (GTK_WIDGET (self));
     }
 }